package Paper;

public class TestPaper implements Paper {
    //每行字符数
    private int charPerLine=16;

    public void setCharPerLine(int charPerLine) {
        this.charPerLine = charPerLine;
    }

    public void setLintPerPage(int lintPerPage) {
        this.lintPerPage = lintPerPage;
    }

    private int lintPerPage=5;
    private String content="";
    private int posX=0;
    private int posY=0;
    private int posP=1;
    public String getContent(){
        String ret=this.content;
        //补齐本页空行，并显示页码
        if(!(posX==0 && posY==0)){
            int count=lintPerPage-posY;
            for (int i=0;i<count;++i){
                ret += Paper.newline;
            }
            ret +="== 第"+posP+"页 ==";
        }
        return  ret;
    }

    @Override
    public void putInChar(char c) {
        content +=c;
        ++posX;
        //判断是否换行
        if(posX==charPerLine){
            content+= Paper.newline;
            posX=0;
            ++posY;
        }
        //判断是否翻译
        if(posY==lintPerPage){
            content+="== 第"+posP+"页 ==";
            content+= Paper.newline+ Paper.newline;
            posY=0;
            ++posP;
        }
    }
}
